<?php
include_once("user_dao_base.php");

class user_dao extends user_dao_base
{
	function get_user_by_name($name)
	{
		try
		{
			$dbh = new PDO(Constants::$connectionString, Constants::$username, Constants::$password);
			$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
			$dbh->beginTransaction();
			
			$stmt = $dbh->prepare("SELECT * FROM  user u WHERE u.name = :user_name");
			$stmt->bindParam(':user_name', $name);
			$stmt->execute();
			
			$u = null;
			if($row = $stmt->fetch())
			{
				$u = new user($row["user_id"],$row["name"],$row["password"],$row["address"],$row["phone"],$row["email"],$row["fax"]);
			}
			
			$dbh->commit();
			$dbh = null;
			return $u;
		}
		catch(PDOException $e)
		{
			echo '<br />' . $e->getMessage();
			$dbh->rollback();
		}	
	}
}
?>